package com.android.superobstacleavoider;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorEvent;
import android.hardware.SensorEventListener;
import android.hardware.SensorManager;

public class AccelerometerHandler implements SensorEventListener {
	private Vector3 m_acc = Vector3.ZERO;

	public AccelerometerHandler(Context a_context) {
		SensorManager sm = (SensorManager) a_context
				.getSystemService(Context.SENSOR_SERVICE);
		if (sm.getSensorList(Sensor.TYPE_ACCELEROMETER).size() != 0) {
			Sensor accelerometer = sm.getSensorList(Sensor.TYPE_ACCELEROMETER)
					.get(0);
			sm.registerListener(this, accelerometer,
					SensorManager.SENSOR_DELAY_GAME);
		}
	}

	@Override
	public void onAccuracyChanged(Sensor sensor, int accuracy) {

	}

	@Override
	public void onSensorChanged(SensorEvent event) {
		m_acc.X = event.values[0];
		m_acc.Y = event.values[1];
		m_acc.Z = event.values[2];
	}

	public Vector3 getAcc() {
		return m_acc;
	}

}
